/**
 * 用户中心重置密码
 */
import {
	request,
	base_api
} from '@/api/request/index.js'
import local_userinfo from '@/util/user/local-userinfo.js'


export default {
	resetLoginPwd(phone, sessionid, code, newpwd,confirmpwd) {

		let error = ""

		if (!sessionid) error = "登录已经失效，请重新登录"
		else if (!code) error = "缺少手机短信验证码"
		else if (!newpwd) error = "请输入你想登录的密码"
		else if(newpwd.length<6) error = "登录密码长度最低6位"
		else if(newpwd != confirmpwd)error = "两次输入的密码不一致"
		if (error) return uni.showToast({
			title: error,
			mask: true,
			duration: 1500,
			icon: 'none'
		});

		uni.showLoading({
			mask: true
		})


		request.get({
			data: {
				c: 'UserController',
				m: 'updateUserPwd',
				phone: phone,
				sessionid: sessionid,
				code: code,
				firstpwd:newpwd,
				confirmpwd: confirmpwd,
			}
		}).then(res => {
			if (res.Status === 'ok') {
				local_userinfo.delUserinfo()
				uni.showModal({
					content: '设置成功，请重新登录',
					showCancel: false,
					success() {
						let wanttoUrlCopy = '../../pages/tabBar/user'
						let noLogin = () => {
							let jumpUrl = ''
							// #ifdef H5
							jumpUrl = '../../pages/login/common'
							// #endif
							// #ifndef H5
							jumpUrl = '../../pages/login/quick'
							// #endif
							uni.navigateTo({
								url: jumpUrl + '?redirect=' + wanttoUrlCopy
							})
						}
						noLogin();
					}
				})
			}else {
				uni.showModal({
					content: res.Msg,
					showCancel: false
				})
			}
		}).catch(error => {
			uni.showModal({
				content: '网络异常，请刷新重试',
				showCancel: false
			})
		})
	}
}
